<?php

// 查询搜索
// p  
// v
// type
// sid
// desc  押金高/低 价格高/低
// 
$json = array('status'=>'ok','msg'=>'ok','data'=>'');

$params = $this->params();
$sys = $this->website['class']['unity']->configura('sys');

$p = $params['p']??1;
$type=$params['type']??'all';
$v = $params['v']??'';
$sid=$params['sid'];
$desc=$params['desc']??'';

$where = ['sid = ? '];
$whereV= [$sid];


if(!($params['sid']??false)){
  $json['data'] = array('data'=>[]);
}else{
  $json['status'] = 'ok';
  $json['msg'] = 'ok';
  $this->website['class']['db']
       ->table('product')
       ->page($p)
       ->num($sys['pagingnum']);
  $descArr  = [];
  switch($type){
    case 'hot'://爆款
      $descArr[] = 'sales desc';
      break;
    case 'cut'://底价专区
      $descArr[] = 'price asc';
      break;
    case 'huabei'://花呗专区
      $where[] = 'huabei = 1';
      break;
    case 'all'://所有商品
    case 'new'://最新上架
    default:
      $descArr[] = 'id desc';
  }
  if($desc){
    $descArr[]=$desc;
  }
  if(!count($descArr)){
    $descArr[] = 'id desc';
  }


  if($v){
    $where[] = 'tit like ?';
    $whereV[] = '%'.$v.'%';
  }

  $json['data'] = $this->website['class']['db']
                ->where(implode(' and ',$where),$whereV)
                ->order(implode(',',$descArr))
                ->paging();
}




$this->json_encode_encrypt($json);